<?php
	
	class GP_page_product extends GP_controleur
	{
		var $controleur;
		var $db;
		var $nom;
		var $description;
		var $ligne;
		
		function __construct()
		{
			global $page;
			$this -> controleur = parent::getInstance($page);
		}
		
		function get_product($id)
		{
			$requete = "SELECT id, id_line, name, num_image, link_eshop, type, contenance, description, fragrances, alt_page_product, meta_keywords, meta_description, page_title FROM _fo_products WHERE id = $id";
			$res = $this -> db -> fetchArray_one($requete);
			$this -> nom = aff_fo($res['name']);
			$this -> description = aff_fo($res['description']);
			$this -> ligne = aff_fo($res['id_line']);
			$this -> setvar('titre', $res['page_title']);
			$this -> setvar('meta_keywords', $res['meta_keywords']);
			$this -> setvar('meta_description', $res['meta_description']);
			return $res;
		}
		
		function afficher()
		{			
			global $page, $urirw;
			
			// si url rewrite
			if (strlen($urirw))
			{
				$pagerw = fakeurl($urirw);
				$htmltmp = $this -> controleur -> htmlrw('header');
				$htmltmp .= $this -> controleur -> htmlrw($page);
				$htmltmp .= $this -> controleur -> htmlrw('footer');
				savefile($pagerw, $htmltmp);
				if (!IS_IE)
					header("HTTP/1.1 301 Moved Permanently");
				include($urirw);
			}
			else
			{
				$this -> controleur -> add_html('header');
				$this -> controleur -> add_html($page);
				$this -> controleur -> add_html('footer');
			}
		}
		
		function setvar($var, $val)
		{
			global $urirw;
			if (strlen($urirw))
				$this -> $var = $val;
			else
				$this -> controleur -> $var = $val;
		}
	}
	
	// On définit les id des parfums avec lien échantillon
	$echantillons = array(
		4,
		7
	);
	
	$page_product = new GP_page_product;
	$gp_request = GP_secure::getInstance();
	$id = $gp_request -> Get('id', $GLOBALS["id"]);
	if (strstr($id, '-'))
		list($id, $dummy) = explode('-', $id, 2);
	$is_sample = false;
	
	if (in_array($id, $echantillons))
		$is_sample = true;
	
	$page_product -> db = GP_db::getInstance(BDD_DSN, BDD_UTILISATEUR, BDD_MOT_DE_PASSE);
	$product = array();
	if (is_numeric($id))
		$product = $page_product -> get_product($id);
	if (!count($product))
		header('Location: ' . URL_SITE . 'error.html');

	$page_product -> setvar('is_sample', $is_sample);
	$page_product -> setvar('product', $product);
	$page_product -> afficher();
?>